#include<iostream>
#include<conio.h>
#include<graphics.h>
#include<string.h>
using namespace std;

void ShowText(int x, int y, int width, int height, char* str) {
	int left, top, right, bottom;
	left = x+1;
	top = y+1;
	right = x + width-1;
	bottom = y + height-1;
	RECT r = { left, top, right, bottom };

	int h = textheight(str);
	int w = 0;
	int nextw = 0;
	settextcolor(BLACK);
	setbkmode(TRANSPARENT);
	
	//cout << "h:" << h << " ";

	int i = 0;
	int j = 0;
	char c=str[i];
	char line[128] = {0};
	char* l = line;
	while (c != '\0') {
		//cout << 1 << " ";
		r = { left, top, right, bottom };
		if (bottom - top < h * 2) {
			drawtext(_T(str + i), &r, DT_WORDBREAK | DT_WORD_ELLIPSIS);
			break;
		}
		while (j < 128) {
			line[j] = c;
			if (c == '\0')break;
			w += textwidth(c);
			c = str[++i];
			j++;
			nextw = w + textwidth(c);
			if (nextw > width || c == '\r' || c == '\n') {
				if (c == '\r' || c == '\n') c = str[++i];
				line[j + 1] = '\0';
				w = 0;
				j = 0;
				break;
			}
		}
		drawtext(_T(l), &r, DT_WORDBREAK);
		top = top + h;
	}
	return;
}

